// $(document).ready(function () {

    $("#jqGrid").jqGrid({
        url: select_url + 'view_warn_config',
        editurl: edit_url + 'warn_config',
        mtype: 'POST',
        datatype: "json",
        colModel: [
            {
                label: '设备编号',
                name: 'deviceid',
                width: 100,
                key: true,
                editable: true,
                editrules : { required: true},
                // readonly:true,
                edittype:"select",
                editoptions: {
                    dataUrl: the_url + "some/device", //已有设备选择
                    // datatype:"json",
                    buildSelect: function (data) {
                        return data;
                    }
                }
            },
            {
                label : '客户名称',
                name: 'clientname',
                width: 100,
                // editable: true,
                readonly:true
            },
            {
                label : '报警类型',
                name: 'warn_type',
                width: 110,
                editable: true,
                edittype:'select',formatter : 'select',
                editoptions : {
                    value:"0:不报警; 1:上限报警; 2:下限报警; 3:上下限报警"
                }
            },
            {
                label: '弹出提示',
                name: 'hint',
                width: 70,
                editable: true,
                edittype:'select',formatter : 'select',
                editoptions : {
                    value:"1 : 是; 0 : 否"
                }
            },
            {
                label : '声音提示',
                name: 'hintvoice',
                width: 70,
                editable: true,
                edittype:'select',formatter:'select',
                editoptions : {
                    value:"1 : 是; 0 : 否"
                }
            },
            {
                label : '声音提示URL',
                name: 'voicefile',
                width: 150,
                editable: true,
                // edittype:'file'
                edittype:"select",
                editoptions: {
                    dataUrl: the_url + "mp3voicelist", //声音选择
                    // datatype:"json",
                    buildSelect: function (data) {
                        data = eval(data); //字符串 转 对象数组
                        var voice = "<select>";
                        for(var i=0; i<data.length; i++){
                            voice += "<option>"+ data[i].name +"</option>"
                        }
                        voice += "</select>";
                        return voice;
                    }
                }
            },
            {
                label: '短信报警',
                name: 'message_warn',
                width: 70,
                editable: true,
                edittype:'select',formatter : 'select',
                editoptions : {
                    value:"1 : 是; 0 : 否"
                }
            },
            {
                label: '报警电话(1~5个)',
                name: 'warn_tele',
                width: 250, fixed: true,
                editable: true,
                edittype:'textarea',
                editoptions : {
                    rows:"5",
                    cols:"45",
                    style:'height:auto!important'
                }
            },
            {
                label: '创建账号',
                name: 'account',
                width: 100,
                editable: true
            },
            {
                label: '报警时间/报警事件创建时间？',
                name: 'time',
                width: 150,
                // editable: true,
                readonly: true,
                fixed: true, formatter: 'date',
                formatoptions: {srcformat:'Y-m-d H:i:s',newformat:'Y-m-d H:i:s'},
            },
            {//行编辑
                label: "操作",
                name: "actions",
                width: 100,
                formatter: "actions",
                formatoptions: {
                    keys: true,
                    editOptions: {},
                    addOptions: {},
                    delOptions: {}
                }       
            }
        ],

        jsonReader: {
            root: 'rows',
            repeatitems : false,
            id: "0"
        },
        rowNum:10,
        rowList:[10,20,30],
        sortname: 'deviceid',
        sortorder : 'desc',//倒序
        viewrecords: true,//记录数
        rownumbers: true, //行序号
        rownumWidth: 25,
        multiselect: true,//复选框
        width: "100%",
        height: 350,
        pager: "#jqGridPager"
    });

    //弹框模板
    var template = "<div style='margin-left:15px;'><div> 设备编号 <sup>*</sup>:</div><div>{deviceid} </div>";
    template += "<div> 报警类型: </div><div>{warn_type} </div>";
    template += "<div> 是否提示:</div><div> {hint} </div>";
    template += "<div> 声音提示: </div><div>{hintvoice} </div>";
    template += "<div> 声音url: </div><div>{voicefile} </div>";
    template += "<div> 短信报警: </div><div>{message_warn} </div>";
    template += "<div> 报警电话:</div><div> {warn_tele} </div>";
    // template += "<div> 报警时间: </div><div>{time} </div>";
    template += "<div> 创建账号:</div><div> {account} </div>";
    template += "<hr style='width:100%;'/>";
    template += "<div> {sData} {cData}  </div></div>";

    
    //分页
    $('#jqGrid').navGrid('#jqGridPager',
        // the buttons to appear on the toolbar of the grid
        { edit: true, add: true, del: true, search: false, refresh: true, view: false, position: "left", cloneToTop: false },
        // Edit Dialog
        {
            editCaption: "修改报警信息",
        },
        // Add Dialog
        {
            addCaption: "添加报警信息",
        }
    );

    //查询
    var client_mask = $("#s_clientname").val();
    gridReload("view_warn_config?clientname="+client_mask);

    
// });